package com.atguigu.gmall.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.gmall.product.client.ProductFeignClient;
import org.springframework.ui.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.thymeleaf.TemplateEngine;

import java.util.List;

@Controller
public class IndexController {


    @Autowired
    private ProductFeignClient productFeignClient;

    @Autowired
    private TemplateEngine templateEngine;

    /***
     * 渲染首页
     * @param model
     * @return
     */
    @GetMapping({"/", ""})
    public String indexHtml(Model model) {
        //1.远程调用商品服务获取首页需要分类数据
        List<JSONObject> list = productFeignClient.getBaseCategoryList();
        model.addAttribute("list", list);

        //2.todo 调用广告服务获取广告列表

        //3.todo 调用推荐服务获取推荐商品

        //4.todo 调用运营服务获取热卖商品/新品等  如果有多项数据获取改串行为并行提交效率
        return "/index/index";
    }

}
